package com.mock.action.organisation.supportingmaterial;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.mock.dao.SupportingMaterialDao;
import com.mock.dao.SupportingMaterialTypeDao;
import com.mock.dao.impl.SupportingMaterialDaoImpl;
import com.mock.dao.impl.SupportingMaterialTypeDaoImpl;
import com.mock.model.SupportingMaterial;
import com.mock.model.SupportingMaterialType;
import com.opensymphony.xwork2.ActionSupport;

public class EditSupportingMaterialAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String execute() throws Exception {
		supportingMaterial = supportingMaterialDao.getById(supportingMaterialId);
		generateData();
		return SUCCESS;
	}
	
	public String update() throws Exception {
		SupportingMaterial supportingMaterial1 = supportingMaterialDao.getById(supportingMaterialId);
		supportingMaterial1.setUrl(url);
		supportingMaterial1.setDescription(description);
		supportingMaterial1.setSupportingMaterialType(supportingMaterialTypeDao.getById(supportingMaterialType));
		supportingMaterialDao.update(supportingMaterial1);
		return SUCCESS;
	}
	
	public String markActive() throws Exception {		
		SupportingMaterial supportingMaterial2 = supportingMaterialDao.getById(supportingMaterialId);
		supportingMaterial2.setActive(false);
		supportingMaterialDao.update(supportingMaterial2);
		return SUCCESS;
	}
	
	public void generateData() {		
		supportingMaterialTypes = supportingMaterialTypeDao.getAllSupportingMaterialTypes();
	}
	
	private long organisationId = -1L;
	private long supportingMaterialId = -1L;
	
	private List<SupportingMaterialType> supportingMaterialTypes = new ArrayList<SupportingMaterialType>();
	private SupportingMaterialTypeDao supportingMaterialTypeDao = new SupportingMaterialTypeDaoImpl();
	private SupportingMaterialDao supportingMaterialDao = new SupportingMaterialDaoImpl();
	
	private SupportingMaterial supportingMaterial;
	private String url;
	private String description;
	private Long supportingMaterialType;
	private String addedBy;
	private Date addedDate;

	public long getOrganisationId() {
		return organisationId;
	}

	public void setOrganisationId(long organisationId) {
		this.organisationId = organisationId;
	}

	public long getSupportingMaterialId() {
		return supportingMaterialId;
	}

	public void setSupportingMaterialId(long supportingMaterialId) {
		this.supportingMaterialId = supportingMaterialId;
	}

	public List<SupportingMaterialType> getSupportingMaterialTypes() {
		return supportingMaterialTypes;
	}

	public void setSupportingMaterialTypes(
			List<SupportingMaterialType> supportingMaterialTypes) {
		this.supportingMaterialTypes = supportingMaterialTypes;
	}

	public SupportingMaterial getSupportingMaterial() {
		return supportingMaterial;
	}

	public void setSupportingMaterial(SupportingMaterial supportingMaterial) {
		this.supportingMaterial = supportingMaterial;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Long getSupportingMaterialType() {
		return supportingMaterialType;
	}

	public void setSupportingMaterialType(Long supportingMaterialType) {
		this.supportingMaterialType = supportingMaterialType;
	}

	public String getAddedBy() {
		return addedBy;
	}

	public void setAddedBy(String addedBy) {
		this.addedBy = addedBy;
	}

	public Date getAddedDate() {
		return addedDate;
	}

	public void setAddedDate(Date addedDate) {
		this.addedDate = addedDate;
	}
	
}
